package com.hnhcyy.goods.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hnhcyy.goods.mapper.SpkfklackMapper;
import com.hnhcyy.goods.pojo.Spkfklack;
import com.hnhcyy.goods.service.SpkfklackAdminService;

/**
 * 缺货service 用于后台
 * @author gesh
 *
 */
@Service
public class SpkfklackAdminServiceImpl implements SpkfklackAdminService {
	
	@Autowired
	SpkfklackMapper spkfklackMapper;
	
	public static final ObjectMapper MAPPER = new ObjectMapper();
	
	/**
	 * 查询缺货记录列表
	 */
	@Override
	public String listSpkfklack(Spkfklack queryParam) {
		
		System.out.println("-=-=-=-" + queryParam.toString());

		List<Spkfklack> list = spkfklackMapper.listSpkfklack(queryParam);

		// 转化为json字符串返回，因为admin端调用用的是原生feign，直接返回List和Mapper会提示解码错误

		String result = "";
		try {
			result = MAPPER.writeValueAsString(list);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}

		System.out.println("---->" + result);

		return result;
	}
	
	/**
	 * 插入缺货记录
	 */
	@Override
	public String insertSpkfklack(Spkfklack spkfklack) {
		
		int insertResult = spkfklackMapper.insertSpkfklack(spkfklack);
		return insertResult + "";
	}

	/**
	 * 更新缺货记录
	 */
	@Override
	public String updateSpkfklack(Spkfklack spkfklack) {
		
		int updateResult = spkfklackMapper.updateSpkfklack(spkfklack);
		
		return updateResult + "";
	}

}
